<!DOCTYPE html>
<html> 
<head>
<title>3.Ukol</title>
<meta charset="utf-8">
<style>
   .modra{background-color:red;}
   .oranz{background-color:orange;}
   .ruz {background-color:pink;}
   .cer{color:red;}
</style>     

</head>               
<body>
 
<?php
if (!empty($_GET)){
	$err = array();

if (!is_string($_GET['jmeno'])||count($_GET['jmeno'])<1){
		$err['jmeno'] = 'Špatné jméno.';
	}
  if (!is_numeric($_GET['vyska']) || $_GET['vyska']<=0){
		$err['vyska'] = 'Špatná vyska.';
	}
	    	
	if (!is_numeric($_GET['weight']) || $_GET['weight']<=0){
		$err['weight'] = 'Špatná váha.';
	}
	
}

$showForm = true;


if (isset($err)){
	if (!empty($err)){
		$showForm = true;
	
		foreach ($err as $current){
			echo "<div style='background-color: darkred;font-size:2em;'>  " . $current . "</div><br/>";
		}
	}
	else{
	    	
	    	$bmi = $_GET['weight'] / ($_GET['vyska'] * $_GET['vyska']);
	}
	$showForm = false;
}

?>



<?php
if ($showForm){
?>

<form action="index.php" method="get">
	

	<br/><br/>

	<label for="jmeno"> Jmeno </label>
	<input type="text" id="jmeno" name="jmeno" value="<?php echo $_GET['jmeno'];?>">
		
	<br/><br/>
	<label for="vyska"> Výška </label>
	<input type="text" id="vyska" name="vyska" value="<?php echo $_GET['vyska'];?>">

	<br/><br/>
	<label for="weight"> Váha </label>
	<input type="text" id="weight" name="weight" value="<?php echo $_GET['weight'];?>">
   <br/><br/>

	<input type="submit" value="Vypočítat">
</form>

<?php
}else{ // else if ($showForm)
echo "<table border=1>";
	echo "  Vaše bmi je $bmi .";
  echo "<br>";
  if($bmi < 18.5)
   {
   echo "<tr><td><div class=\"modra\">". Podváha."</div></td></tr>";
   }
    
    if (25 >= $bmi && $bmi >= 18.5 ) 
   {
  echo "<tr><td>Normal</td></tr>";
   }
   if ($bmi > 25)
   {
   echo  "<tr><td><div class=\"modra\">". Nadváhu."</div></td></tr>";
   }
      echo "<tr><td>Jemno:  ". $_GET['jmeno']."</td></tr>";
      echo "<tr><td>Vyska:  ". $_GET['vyska']."M</td></tr>";
      echo "<tr><td>Váha:   ". $_GET['weight']."Kg</td></tr>" ;
  echo   "</table> "; 
} // end if ($showForm)
?>

</body>
</html> 